/******************************************************************************
 *
 * MotionViewer
 * Copyright (C) 2007 Sangyoon Lee, Electronic Visualization Laboratory, 
 * University of Illinois at Chicago
 *
 * This software is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either Version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License along
 * with this software; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Questions or comments about MotionViewer should be directed to 
 * cavern@evl.uic.edu
 *
 *****************************************************************************/

#ifndef __VICONRTDATA_H__
#define __VICONRTDATA_H__
#include <ogreplatform.h>
#pragma warning(disable:4267)	

#ifdef _WIN32
#include <winsock2.h>
#else
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#define INVALID_SOCKET  -1
#define SOCKET_ERROR    -1
#endif

#include "ViconMotionDataSet.h"

class ViconRTData: public ViconMotionDataSet
{
public:
	ViconRTData();
	virtual ~ViconRTData();

	virtual void update(float addedTime);
	virtual void connectToSource(char* source) { connectRT(source); }
	virtual void getMarkerPosition(int id, float* pos);
	virtual void getBodyTranslation(int id, float* trans, bool global = true);
	virtual void getBodyRotation(int id, float* rot, bool global = true);
	virtual void getBodyQuaternion(int id, float* qt, bool global = true);

	bool	connectRT(char* addr);
	bool	disconnectRT();
	
protected:

	virtual void updateDebug();

	bool	initSocket(char* addr);
	bool	connectToEngine();

	bool	m_bConnected;
	float	m_fElapsedTime;

#ifdef _WIN32
	SOCKET	SocketHandle;
#else
	int		SocketHandle;
#endif

	char*	pBuff;
	int		bufferSize;
	char	buff[2040];
	long int size;
	int		FrameChannel;
	bool	m_bViconRT;
	
	std::vector< std::string >		m_vInfo;
	std::vector< MarkerData >		m_vMarkerData;
	std::vector< BodyData >			m_vBodyData;
};

#endif